<?php
namespace project\db;

use mysqli;
use mysqli_sql_exception;

/**
 * 数据库连接类
 */
class DB
{
  private static $mysqli = null;

  public static function mysqli()
  {
    if (self::$mysqli !== null) {
      return self::$mysqli;
    }

    try {
      return self::$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    } catch (mysqli_sql_exception $e) {
      exit($e->getMessage());
    }
  }
}